//
//  ChooseBtnFindView.m
//  HubeiHotel
//
//  Created by LiBenCan on 17/11/20.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "ChooseBtnFindView.h"

@implementation ChooseBtnFindView

-(instancetype)initWithFrame:(CGRect)frame TitleArr:(NSArray *)titleArr
{
    if (self = [super initWithFrame:frame]) {
        
        //循环添加按钮
        for (int i = 0; i<titleArr.count; i++) {
            
            UIButton *titleBtn = [TomamaUI createButton:UIButtonTypeCustom Frame:CGRectMake(SCREENW/titleArr.count*i,0,SCREENW/titleArr.count, 38*screenW_6) targ:self sel:@selector(SelectBtn:) titleColor:TextBlack font:[UIFont systemFontOfSize:15*screenW_6] title:titleArr[i] image:@"" backGroundImage:@""];
            titleBtn.tag = 10+i;
            [self addSubview:titleBtn];
            //选中的颜色
            [titleBtn setTitleColor:[UIColor colorWithHexString:@"#5bc3c2"] forState:UIControlStateSelected];
        }
        
        float labWidth = [ToolViewVC getlabWidth:titleArr[0] WithFont:15*screenW_6];
        //线条
        _linelab = [TomamaUI createLabel:CGRectMake(SCREENW/2/titleArr.count-labWidth/2,38*screenW_6,labWidth,2*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:1] textColor:[UIColor colorWithHexString:@"#7ccfce"] text:@""];
        _linelab.backgroundColor = [UIColor colorWithHexString:@"#7ccfce"];
        [self addSubview:_linelab];
    }
    return self;
}

//点击事件
-(void)SelectBtn:(UIButton *)btn
{
    btn.selected = YES;
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *selecBtn = (UIButton *)view;
            selecBtn.selected = (view.tag == btn.tag)?YES:NO;
        }
    }
    _linelab.center = CGPointMake(btn.center.x, 38*screenW_6);
    if (_chooseBtnBlock) {
        self.chooseBtnBlock(btn.tag-10);
    }
}
@end
